
<include file="public@header" />
</head>
<body>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li><a href="{:url('/company/admin_member_group/index')}">所有群组</a></li>
		<li class="active"><a>群组添加</a></li>
	</ul>
	<form method="post" class="form-horizontal margin-top-20  js-ajax-form" action="{:url('/company/admin_member_group/addPost')}">

		<div class="form-group">
			<label for="name" class="col-sm-2 control-label"><span class="form-required">*</span>名称</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="name" name="post[name]">
			</div>


		</div>

		<div class="form-group">

			<label for="owner_name" class="col-sm-2 control-label"><span class="form-required">*</span>群主姓名</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="owner_name" name="post[owner_name]" value="">
			</div>


			<label for="owner_wx" class="col-sm-2 control-label"><span class="form-required">*</span>群主微信</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="owner_wx" name="post[owner_wx]" value="">
			</div>


		</div>
		<div class="form-group">
			<label for="owner_phone" class="col-sm-2 control-label"><span class="form-required">*</span>群主电话</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="owner_phone" name="post[owner_phone]" value="">
			</div>



		</div>


		<div class="form-group">
			<label for="create_date" class="col-sm-2 control-label"><span class="form-required">*</span>成立时间</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control js-bootstrap-date" id="create_date" name="post[create_date]" value="">
			</div>

			<label for="person_count" class="col-sm-2 control-label"><span class="form-required">*</span>人数</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="person_count" name="post[person_count]" value="">
			</div>


		</div>




		<div class="form-group">
			<label for="description" class="col-sm-2 control-label">描述</label>
			<div class="col-md-6 col-sm-10">
					<textarea class="form-control" name="post[description]" id="description" style="height: 50px;"
							  placeholder="请填写问题描述"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label for="province" class="col-sm-2 control-label"><span class="form-required">*</span>所在地区</label>
			<div class="col-md-2 col-sm-10">


				<select class="form-control" id="province" name="post[province_id]" >
					<php>$select = $districts['options'][0]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][0]['options']" item="vo">
						<php>$select = $districts['options'][0]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<div class="col-md-2 col-sm-10">

				<select class="form-control" id="city" name="post[city_id]" >
					<php>$select = $districts['options'][1]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][1]['options']" item="vo">
						<php>$select = $districts['options'][1]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="country" name="post[country_id]" >
					<php>$select = $districts['options'][2]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][2]['options']" item="vo">
						<php>$select = $districts['options'][2]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>



			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="area" >
					<php>$select = $districts['options'][3]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][3]['options']" item="vo">
						<php>$select = $districts['options'][3]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<input type="hidden" id="province_name" name="post[province_name]" value="">

			<input type="hidden" id="city_name" name="post[city_name]" value="">

			<input type="hidden" id="country_name" name="post[country_name]" value="">

			<input type="hidden" id="district_id" name="post[district_id]" value="{$default_district}">
			<input type="hidden" id="district_name" name="post[district_name]" value="{$districts['name']}">


		</div>


		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<input type="hidden" name="post[user_id]" value="{$Think.session.user.id}" />
				<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
				<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
			</div>
		</div>
	</form>
</div>


<link rel="stylesheet" href="__STATIC__/js/select2/css/select2.min.css">

<script src="__STATIC__/js/select2/js/select2pinyin.js?v=201802271547"></script>

<script>

    $(function () {
        var $province = $("#province");
        var $city = $("#city");
        var $country = $("#country");
        var $area = $("#area");
        var $district_id = $("#district_id");
        var $district_name = $("#district_name");

        var empty = "<option value='' data-text=''>请选择</option>";

        $province.select2();
        $city.select2();
        $country.select2();
        $area.select2();

        $province.on('change', function () {
            var province = $province.find("option:selected");
            if (province.val().length == 0) {
                $city.html(empty);
                $country.html(empty);
                $area.html(empty);
                $district_id.val(0);
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: province.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $city.html(options);
                    $country.html(empty);
                    $area.html(empty);
                });
                $district_id.val(province.val());
            }
            $district_name.val(province.data("text"));
        });
        $city.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            if (city.val().length == 0) {
                $country.html(empty);
                $area.html(empty);
                $district_id.val(province.val());
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: city.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $country.html(options);
                    $area.html(empty);
                });
                $district_id.val($city.val());
            }
            $district_name.val(province.data("text") + city.data("text"));
        });
        $country.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            var country = $country.find("option:selected");
            if (country.val().length == 0) {
                $area.html(empty);
                $district_id.val(city.val());
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: country.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $area.html(options);
                });
                $district_id.val(country.val());
            }
            $district_name.val(province.data("text") + city.data("text") + country.data("text"));
        });
        $area.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            var country = $country.find("option:selected");
            var area = $area.find("option:selected");
            $district_name.val(province.data("text") + city.data("text") + country.data("text") + area.data("text"));
            if (area.val().length == 0) {
                $district_id.val(country.val());
            } else {
                $district_id.val(area.val());
            }
        });

    })

    $("form").submit(function(e){


        $("#province_name").val($("#province").find("option:selected").data("text"));

        $("#city_name").val($("#city").find("option:selected").data("text"));
        $("#country_name").val($("#country").find("option:selected").data("text"));


        //return false;
    });

</script>

<script src="__STATIC__/js/admin.js"></script>
</body>
</html>